package com.tudouji.project.mt.http.request;

import com.google.gson.reflect.TypeToken;
import com.meituan.sdk.MeituanRequest;
import com.meituan.sdk.MeituanResponse;
import com.meituan.sdk.annotations.ApiMeta;
import com.meituan.sdk.internal.exceptions.MtSdkException;
import com.meituan.sdk.internal.utils.JsonUtil;
import com.tudouji.project.mt.http.response.DishSaleResponse;
import com.tudouji.project.mt.http.response.FoodConsumptionResponse;
import lombok.Data;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.lang.reflect.Type;

/**
 * 门店-菜品销售统计
 */
@ApiMeta(
        path = "/rms/data/api/v1/poi/dish_sale/query",
        businessId = 18,
        apiVersion = "",
        apiName = "",
        needAuth = true
)
@Data
public class DishSaleRequest implements MeituanRequest<DishSaleResponse> {

    //所属配送中心ID
    private Long orgId;

    //入库时间-开始(毫秒时间戳)
    private Long startDate;

    //入库时间-结束(毫秒时间戳)
    private Long endDate;

    //页码,从1开始
    private Integer pageNo;

    //页大小,1~200
    private Integer pageSize;

    //加料是否单独统计
    private Integer fedIsAloneSale;

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public MeituanResponse<DishSaleResponse> deserializeResponse(String response) {
        Type type = new TypeToken<MeituanResponse<DishSaleResponse>>(){}.getType();
        return JsonUtil.fromJson(response, type);
    }
    @Override
    public String serializeToJson() {
        return JsonUtil.toJson(this);
    }
}
